/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.rocketmq.example.quickstart;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

import java.util.Date;


public class Producer {
    public static void main(String[] args) throws MQClientException, InterruptedException {


        DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");

        producer.setNamesrvAddr("localhost:9876");

        producer.start();

        try {
            for (int i = 0; i < 10; i++) {
                String body = "{\"spiderUser\":\"{\"accountNonExpired\":true,\"accountNonLocked\":true,\"authorities\":[{\"authority\":\"APP\"},{\"authority\":\"APP_AI_STORE_DEVICE_TARGET\"},{\"authority\":\"APP_AI_STORE_DEVICE_TARGET_RESULT_CHECK\"},{\"authority\":\"APP_AI_STORE_DEVICE_TARGET_RESULT_DETAIL\"},{\"authority\":\"APP_AI_STORE_DEVICE_TARGET_RESULT_LIST\"},{\"authority\":\"APP_AI_STORE_EVENT_CENTER\"},{\"authority\":\"APP_AI_STORE_EVENT_CENTER_ADD\"},{\"authority\":\"APP_AI_STORE_EVENT_CENTER_LIST\"},{\"authority\":\"APP_AI_STORE_EVENT_CENTER_VIEW\"},{\"authority\":\"APP_AI_STORE_PATROL\"},{\"authority\":\"APP_AI_STORE_PATROL_ADD\"},{\"authority\":\"APP_AI_STORE_PATROL_DETAIL\"},{\"authority\":\"APP_AI_STORE_PATROL_LIST\"},{\"authority\":\"APP_AI_STORE_SIGN_LIST\"},{\"authority\":\"APP_ANALYSIS\"},{\"authority\":\"APP_ANALYSIS_CUSTOMER\"},{\"authority\":\"APP_ANALYSIS_CUSTOMER_DEPT\"},{\"authority\":\"APP_ANALYSIS_DATA\"},{\"authority\":\"APP_ANALYSIS_DEVICE_TARGET\"},{\"authority\":\"APP_ANALYSIS_DEVICE_TARGET_DEPT\"},{\"authority\":\"APP_ANALYSIS_EVENT\"},{\"authority\":\"APP_ANALYSIS_EVENT_DEPT\"},{\"authority\":\"APP_ANALYSIS_PASSENGER\"},{\"authority\":\"APP_ANALYSIS_PASSENGER_DEPT\"},{\"authority\":\"APP_ANALYSIS_PASSENGER_RANK\"},{\"authority\":\"APP_ANALYSIS_PATROL\"},{\"authority\":\"APP_ANALYSIS_PATROL_DEPT\"},{\"authority\":\"APP_MANAGER\"},{\"authority\":\"APP_MESSAGE_CENTER\"},{\"authority\":\"APP_MESSAGE_CENTER_LIST\"},{\"authority\":\"APP_MINE\"},{\"authority\":\"APP_PATROL_SHOP\"},{\"authority\":\"APP_SECURITY\"},{\"authority\":\"APP_SECURITY_ALARM\"},{\"authority\":\"APP_SECURITY_ALARM_MSGTAB\"},{\"authority\":\"APP_SECURITY_SETTING_DELETE\"},{\"authority\":\"APP_SECURITY_WARN_LIST\"},{\"authority\":\"APP_SIGN\"},{\"authority\":\"APP_SYSTEM_DEPT\"},{\"authority\":\"APP_SYSTEM_DEPT_ADD\"},{\"authority\":\"APP_SYSTEM_DEPT_EDIT\"},{\"authority\":\"APP_SYSTEM_DEPT_VIEW\"},{\"authority\":\"APP_SYSTEM_DEVICE\"},{\"authority\":\"APP_SYSTEM_DEVICE_ADD\"},{\"authority\":\"APP_SYSTEM_DEVICE_DELETE\"},{\"authority\":\"APP_SYSTEM_DEVICE_EDIT\"},{\"authority\":\"APP_SYSTEM_DEVICE_GROUP\"},{\"authority\":\"APP_SYSTEM_DEVICE_LIST\"},{\"authority\":\"APP_SYSTEM_DEVICE_VIEW\"},{\"authority\":\"APP_SYSTEM_USER\"},{\"authority\":\"APP_SYSTEM_USER_ADD\"},{\"authority\":\"APP_SYSTEM_USER_EDIT\"},{\"authority\":\"APP_SYSTEM_USER_LIST\"},{\"authority\":\"APP_SYSTEM_USER_VIEW\"},{\"authority\":\"APP_VIDEO\"},{\"authority\":\"APP_VIDEO_DEVICE_LIST\"},{\"authority\":\"APP_VIDEO_DEVICE_OPERTION\"},{\"authority\":\"APP_VIDEO_DEVICE_REC\"},{\"authority\":\"APP_VIDEO_DEVICE_SCREEN\"},{\"authority\":\"APP_VIDEO_DEVICE_TALK\"},{\"authority\":\"APP_VIDEO_DEVICE_VIEW\"},{\"authority\":\"APP_VIDEO_DEVICE_VIEW_LOOK\"},{\"authority\":\"NORMAL\"},{\"authority\":\"PC\"},{\"authority\":\"PC_AI_STORE\"},{\"authority\":\"PC_AI_STORE_CUSTOMER\"},{\"authority\":\"PC_AI_STORE_CUSTOMER_MANAGER\"},{\"authority\":\"PC_AI_STORE_CUSTOMER_MANAGER_ADD\"},{\"authority\":\"PC_AI_STORE_CUSTOMER_MANAGER_DETAIL\"},{\"authority\":\"PC_AI_STORE_CUSTOMER_MANAGER_LIST\"},{\"authority\":\"PC_AI_STORE_DEVICE_TARGET\"},{\"authority\":\"PC_AI_STORE_DEVICE_TARGET_ADD\"},{\"authority\":\"PC_AI_STORE_DEVICE_TARGET_DELETE\"},{\"authority\":\"PC_AI_STORE_DEVICE_TARGET_DETAIL\"},{\"authority\":\"PC_AI_STORE_DEVICE_TARGET_LIST\"},{\"authority\":\"PC_AI_STORE_DEVICE_TARGET_RESULT_CHECK\"},{\"authority\":\"PC_AI_STORE_DEVICE_TARGET_RESULT_DETAIL\"},{\"authority\":\"PC_AI_STORE_EVENT_CENTER\"},{\"authority\":\"PC_AI_STORE_EVENT_CENTER_ADD\"},{\"authority\":\"PC_AI_STORE_EVENT_CENTER_LIST\"},{\"authority\":\"PC_AI_STORE_EVENT_CENTER_VIEW\"},{\"authority\":\"PC_AI_STORE_HOTZONEANALYSIS\"},{\"authority\":\"PC_AI_STORE_HOTZONEANALYSIS_LIST\"},{\"authority\":\"PC_AI_STORE_PATROL\"},{\"authority\":\"PC_AI_STORE_PATROL_DETAIL\"},{\"authority\":\"PC_AI_STORE_PATROL_LIST\"},{\"authority\":\"PC_AI_STORE_SIGN\"},{\"authority\":\"PC_AI_STORE_SIGN_LIST\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_RULE\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_RULE_ADD\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_RULE_DELETE\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_RULE_EDIT\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_RULE_VIEW\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_TEMPLATE\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_TEMPLATE_ADD\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_TEMPLATE_COPY\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_TEMPLATE_DELETE\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_TEMPLATE_EDIT\"},{\"authority\":\"PC_AI_STORE_TEMPLATE_MANAGER_TEMPLATE_VIEW\"},{\"authority\":\"PC_ANALYSIS\"},{\"authority\":\"PC_ANALYSIS_DEVICE_TARGET\"},{\"authority\":\"PC_ANALYSIS_EVENTDATA\"},{\"authority\":\"PC_ANALYSIS_PASSENGER\"},{\"authority\":\"PC_ANALYSIS_PATROL\"},{\"authority\":\"PC_BIG_SCREEN\"},{\"authority\":\"PC_MESSAGE_CENTER\"},{\"authority\":\"PC_MESSAGE_CENTER_LIST\"},{\"authority\":\"PC_OPERATION_LOG\"},{\"authority\":\"PC_SECURITY\"},{\"authority\":\"PC_SECURITY_ALARM\"},{\"authority\":\"PC_SECURITY_ALARM_ADD\"},{\"authority\":\"PC_SECURITY_ALARM_DEL\"},{\"authority\":\"PC_SECURITY_ALARM_DETAIL\"},{\"authority\":\"PC_SECURITY_ALARM_EDIT\"},{\"authority\":\"PC_SECURITY_ALARM_MSGTAB\"},{\"authority\":\"PC_SECURITY_ALARM_TASK\"},{\"authority\":\"PC_SECURITY_SETTING\"},{\"authority\":\"PC_SECURITY_SETTING_ADD\"},{\"authority\":\"PC_SECURITY_SETTING_CLOSE\"},{\"authority\":\"PC_SECURITY_SETTING_DELETE\"},{\"authority\":\"PC_SECURITY_SETTING_EDIT\"},{\"authority\":\"PC_SECURITY_SETTING_LIST\"},{\"authority\":\"PC_SECURITY_SETTING_VIEW\"},{\"authority\":\"PC_SECURITY_WARN\"},{\"authority\":\"PC_SECURITY_WARN_BATCH_DELETE\"},{\"authority\":\"PC_SECURITY_WARN_DELETE\"},{\"authority\":\"PC_SECURITY_WARN_LIST\"},{\"authority\":\"PC_SYSTEM\"},{\"authority\":\"PC_SYSTEM_DEPT\"},{\"authority\":\"PC_SYSTEM_DEPT_ADD\"},{\"authority\":\"PC_SYSTEM_DEPT_DELETE\"},{\"authority\":\"PC_SYSTEM_DEPT_EDIT\"},{\"authority\":\"PC_SYSTEM_DEPT_VIEW\"},{\"authority\":\"PC_SYSTEM_DEVICE\"},{\"authority\":\"PC_SYSTEM_DEVICE_EDIT\"},{\"authority\":\"PC_SYSTEM_DEVICE_LIST\"},{\"authority\":\"PC_SYSTEM_DEVICE_VIEW\"},{\"authority\":\"PC_SYSTEM_PARAM\"},{\"authority\":\"PC_SYSTEM_ROLE\"},{\"authority\":\"PC_SYSTEM_ROLE_ADD\"},{\"authority\":\"PC_SYSTEM_ROLE_DELETE\"},{\"authority\":\"PC_SYSTEM_ROLE_EDIT\"},{\"authority\":\"PC_SYSTEM_ROLE_LIST\"},{\"authority\":\"PC_SYSTEM_ROLE_VIEW\"},{\"authority\":\"PC_SYSTEM_SERVICE\"},{\"authority\":\"PC_SYSTEM_SERVICE_PURCHASED\"},{\"authority\":\"PC_SYSTEM_USER\"},{\"authority\":\"PC_SYSTEM_USER_ADD\"},{\"authority\":\"PC_SYSTEM_USER_EDIT\"},{\"authority\":\"PC_SYSTEM_USER_LIST\"},{\"authority\":\"PC_SYSTEM_USER_VIEW\"},{\"authority\":\"PC_VIDEO\"},{\"authority\":\"PC_VIDEO_DEVICE_OPERTION\"},{\"authority\":\"PC_VIDEO_DEVICE_REC\"},{\"authority\":\"PC_VIDEO_DEVICE_SCREEN\"},{\"authority\":\"PC_VIDEO_DEVICE_TALK\"},{\"authority\":\"PC_VIDEO_DEVICE_VIEW_LOOK\"},{\"authority\":\"PC_VIDEO_VIEW\"}],\"bussinesCode\":\"customer\",\"closeliOrgId\":\"168\",\"companyId\":175,\"companyName\":\"2022企业\",\"credentialsNonExpired\":true,\"depts\":[],\"enabled\":true,\"faceAlgorithm\":2,\"guid\":\"d292eaf6-daf5-4089-bc8d-ad3c729c0423\",\"isAdmin\":0,\"isDefaultPassword\":0,\"isPush\":\"111111111\",\"mobile\":\"19122606077\",\"password\":\"N/A\",\"projectCipher\":\"QUlfU1RPUkU=\",\"pushToken\":\"\",\"realName\":\"贰1\",\"roleCode\":\"company_admin\",\"roleName\":\"系统管理员\",\"state\":10,\"sysRoleId\":3,\"systemType\":10,\"terminal\":2,\"userId\":5421,\"userType\":1,\"username\":\"2022test1\"}\",\"deviceToPeopleAndFaceDto\":\"{\"deptId\":5858,\"qrcode\":\"d5\",\"serialNumber\":\"200020060058147\"}\",\"projectEnum\":\"\"AI_STORE\"\"}";
                Message msg = new Message("TopicTest" /* Topic */,
                        "TagA" /* Tag */,
                        (body.substring(0, body.length())).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */
                );
                msg.setStartDeliverTime(System.currentTimeMillis() + (10 * 1000));
                String time= DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss");
                SendResult sendResult = producer.send(msg);


                System.out.printf( time+ ">> i="+  i+" >>>%s%n", sendResult);
            }
        } catch (Exception e) {
            e.printStackTrace();

        }

        /*
         * Shut down once the producer instance is not longer in use.
         */
        producer.shutdown();
    }
}
